﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
 }
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        订单编号：<input id="ordersn" col="ordersn" type="text" />
                    </li>
                    <li>
                        退货类型：<span id="refundType" col="refundType"></span>
                    </li>
                    <li class="select-time">
                        <label>申请时间： </label>
                        <input id="startTime" col="StartTime" type="text" class="time-input" placeholder="开始时间" />
                        <span>-</span>
                        <input id="endTime" col="EndTime" type="text" class="time-input" placeholder="结束时间" />
                    </li>
                    <li class="select-time">
                        <label>处理时间： </label>
                        <input id="PStartTime" col="PStartTime" type="text" class="time-input" placeholder="开始时间" />
                        <span>-</span>
                        <input id="PEndTime" col="PEndTime" type="text" class="time-input" placeholder="结束时间" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        @*<div class="btn-group-sm hidden-xs" id="toolbar">
            <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>*@
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        laydate.render({ elem: '#startTime', format: 'yyyy-MM-dd' });
        laydate.render({ elem: '#endTime', format: 'yyyy-MM-dd' });
        laydate.render({ elem: '#PStartTime', format: 'yyyy-MM-dd' });
        laydate.render({ elem: '#PEndTime', format: 'yyyy-MM-dd' });

        $("#refundType").ysComboBox({ data: ys.getJson(@Html.Raw(typeof(refundType).EnumToDictionaryString())) });

        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/QixingManage/OrderRefundApply/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'refundType', title: '退货类型' ,  formatter: function (value, row, index) {
                    if (row.refundType == "@refundType.A.ParseToInt()") {
                        return "@refundType.A.GetDescription()";
                        } else if (row.refundType == "@refundType.B.ParseToInt()") {
                                 return "@refundType.B.GetDescription()";
                        } else if (row.refundType == "@refundType.C.ParseToInt()") {
                                 return "@refundType.C.GetDescription()";
                        } else if (row.refundType == "@refundType.D.ParseToInt()") {
                                 return "@refundType.D.GetDescription()";
                        } else if (row.refundType == "@refundType.F.ParseToInt()") {
                                 return "@refundType.F.GetDescription()";
                        } else if (row.refundType == "@refundType.E.ParseToInt()") {
                                 return "@refundType.E.GetDescription()";
                        }
                        else if (row.refundType == "@refundType.G.ParseToInt()") {
                                     return "@refundType.G.GetDescription()";
                        }
                        else if (row.refundType == "@refundType.H.ParseToInt()") {
                                     return "@refundType.H.GetDescription()";
                        }
                    }
                },
                { field: 'remark', title: '退货原因' },
                { field: 'createtime', title: '申请时间' },
                { field: 'nickname', title: '退货人' },
                { field: 'ordersn', title: '订单编号' },
                { field: 'amount', title: '退款金额' },
                { field: 'processtime', title: '处理时间' },
                { field: '', title: '操作',formatter: function (value, row, index) {
                        var actions = [];
                    actions.push(' <a class="btn btn-info btn-xs" href="#" onclick="OrderRefundApply(\'' + row.Id + '\')"><i class="fa fa-list-ul"></i>退货查看</a>');
                        return actions.join('');
                    }
                },
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function OrderRefundApply(id) {
         ys.openDialog({
            title:'退货查看',
            content: '@Url.Content("~/QixingManage/OrderRefundApply/OrderRefundApplyForm")' + '?id=' + id,
            width: '1000px',
            height: '750px',
            btn: [],
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/QixingManage/OrderRefundApply/OrderRefundApplyForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/OrderRefundApply/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
